using UnityEngine;

namespace Framework.Scene
{
    public abstract class BaseScene : MonoBehaviour
    {
        protected Framework.UI.ILoadingPanel LoadingPanel { get; private set; }

        private void Awake()
        {
            if (!GameRoot.HaveInstance()) { return; }
            SceneManager sceneManager = FrameworkEntry.GetModule<SceneManager>();
            this.LoadingPanel = sceneManager.LoadingPanel;
            this.LoadingPanel.SetEndCallBack(this.FinishLoadScene);
            sceneManager.Scene = this;
            this.OnCreateScene();
        }

        private void OnDestroy()
        {
            if (!GameRoot.HaveInstance()) { return; }
            OnLeaveScene();
            FrameworkEntry.GetModule<SceneManager>().Scene = null;
        }

        public virtual void FinishLoadScene()
        {
            OnEnterScene();
            FrameworkEntry.GetModule<SceneManager>().CloseLoadingPanel();
            this.LoadingPanel = null;
        }

        public virtual void OnCreateScene()
        {
        }

        public virtual void OnEnterScene()
        {
        }

        public virtual void OnLeaveScene()
        {
        }
    }
}